package org.budo.support.slf4j.logger.console;

import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.Marker;

/**
 * @author Phoenix
 */
public class BudoSlf4jConsoleLogger implements Logger {
    private String name;

    private Logger logger;

    public BudoSlf4jConsoleLogger() {
    }

    public BudoSlf4jConsoleLogger(String name) {
        this.name = name;
    }

    public BudoSlf4jConsoleLogger(String name, Logger logger) {
        this.name = name;
        this.logger = logger;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public boolean isTraceEnabled() {
        return true;
    }

    @Override
    public void trace(String msg) {
        System.out.println(this.name + ": " + msg);
        System.err.println(this.name + ": " + msg);

        if (null != this.logger) {
            this.logger.trace(msg);
        }
    }

    @Override
    public void trace(String format, Object arg) {
        System.out.println(this.name + ":" + format + arg);
        System.err.println(this.name + ":" + format + arg);

        if (null != this.logger) {
            this.logger.trace(format, arg);
        }
    }

    @Override
    public void trace(String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + format + arg1 + arg2);
        System.err.println(this.name + ":" + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.trace(format, arg1, arg2);
        }
    }

    @Override
    public void trace(String format, Object... arguments) {
        System.out.println(this.name + ":" + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.trace(format, arguments);
        }
    }

    @Override
    public void trace(String msg, Throwable t) {
        System.out.println(this.name + ":" + msg + t);
        System.err.println(this.name + ":" + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.trace(msg, t);
        }
    }

    @Override
    public boolean isTraceEnabled(Marker marker) {
        return true;
    }

    @Override
    public void trace(Marker marker, String msg) {
        System.out.println(this.name + ":" + marker + msg);
        System.err.println(this.name + ":" + marker + msg);

        if (null != this.logger) {
            this.logger.trace(marker, msg);
        }
    }

    @Override
    public void trace(Marker marker, String format, Object arg) {
        System.out.println(this.name + ":" + marker + format + arg);
        System.err.println(this.name + ":" + marker + format + arg);

        if (null != this.logger) {
            this.logger.trace(marker, format, arg);
        }
    }

    @Override
    public void trace(Marker marker, String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + marker + format + arg1 + arg2);
        System.err.println(this.name + ":" + marker + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.trace(marker, format, arg1, arg2);
        }
    }

    @Override
    public void trace(Marker marker, String format, Object... argArray) {
        System.out.println(this.name + ":" + marker + format + Arrays.toString(argArray));
        System.err.println(this.name + ":" + marker + format + Arrays.toString(argArray));

        if (null != this.logger) {
            this.logger.trace(marker, format, argArray);
        }
    }

    @Override
    public void trace(Marker marker, String msg, Throwable t) {
        System.out.println(this.name + ":" + marker + msg);
        System.err.println(this.name + ":" + marker + msg);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.trace(marker, msg, t);
        }
    }

    @Override
    public boolean isDebugEnabled() {
        return true;
    }

    @Override
    public void debug(String msg) {
        System.out.println(this.name + ":" + msg);
        System.err.println(this.name + ":" + msg);

        if (null != this.logger) {
            this.logger.debug(msg);
        }
    }

    @Override
    public void debug(String format, Object arg) {
        System.out.println(this.name + ":" + format + arg);
        System.err.println(this.name + ":" + format + arg);

        if (null != this.logger) {
            this.logger.debug(format, arg);
        }
    }

    @Override
    public void debug(String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + format + arg1 + arg2);
        System.err.println(this.name + ":" + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.debug(format, arg1, arg2);
        }
    }

    @Override
    public void debug(String format, Object... arguments) {
        System.out.println(this.name + ":" + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.debug(format, arguments);
        }
    }

    @Override
    public void debug(String msg, Throwable t) {
        System.out.println(this.name + ":" + msg + t);
        System.err.println(this.name + ":" + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.debug(msg, t);
        }
    }

    @Override
    public boolean isDebugEnabled(Marker marker) {
        return true;
    }

    @Override
    public void debug(Marker marker, String msg) {
        System.out.println(this.name + ":" + marker + msg);
        System.err.println(this.name + ":" + marker + msg);

        if (null != this.logger) {
            this.logger.debug(marker, msg);
        }
    }

    @Override
    public void debug(Marker marker, String format, Object arg) {
        System.out.println(this.name + ":" + marker + format + arg);
        System.err.println(this.name + ":" + marker + format + arg);

        if (null != this.logger) {
            this.logger.debug(marker, format, arg);
        }
    }

    @Override
    public void debug(Marker marker, String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + marker + format + arg1 + arg2);
        System.err.println(this.name + ":" + marker + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.debug(marker, format, arg1, arg2);
        }
    }

    @Override
    public void debug(Marker marker, String format, Object... arguments) {
        System.out.println(this.name + ":" + marker + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + marker + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.debug(marker, format, arguments);
        }
    }

    @Override
    public void debug(Marker marker, String msg, Throwable t) {
        System.out.println(this.name + ":" + marker + msg + t);
        System.err.println(this.name + ":" + marker + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.debug(marker, msg, t);
        }
    }

    @Override
    public boolean isInfoEnabled() {
        return true;
    }

    @Override
    public void info(String msg) {
        System.out.println(this.name + ":" + msg);
        System.err.println(this.name + ":" + msg);

        if (null != this.logger) {
            this.logger.info(msg);
        }
    }

    @Override
    public void info(String format, Object arg) {
        System.out.println(this.name + ":" + format + arg);
        System.err.println(this.name + ":" + format + arg);

        if (null != this.logger) {
            this.logger.info(format, arg);
        }
    }

    @Override
    public void info(String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + format + arg1 + arg2);
        System.err.println(this.name + ":" + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.info(format, arg1, arg2);
        }
    }

    @Override
    public void info(String format, Object... arguments) {
        System.out.println(this.name + ":" + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.info(format, arguments);
        }
    }

    @Override
    public void info(String msg, Throwable t) {
        System.out.println(this.name + ":" + msg + t);
        System.err.println(this.name + ":" + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.info(msg, t);
        }
    }

    @Override
    public boolean isInfoEnabled(Marker marker) {
        return true;
    }

    @Override
    public void info(Marker marker, String msg) {
        System.out.println(this.name + ":" + marker + msg);
        System.err.println(this.name + ":" + marker + msg);

        if (null != this.logger) {
            this.logger.info(marker, msg);
        }
    }

    @Override
    public void info(Marker marker, String format, Object arg) {
        System.out.println(this.name + ":" + marker + format + arg);
        System.err.println(this.name + ":" + marker + format + arg);

        if (null != this.logger) {
            this.logger.info(marker, format, arg);
        }
    }

    @Override
    public void info(Marker marker, String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + marker + format + arg1 + arg2);
        System.err.println(this.name + ":" + marker + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.info(marker, format, arg1, arg2);
        }
    }

    @Override
    public void info(Marker marker, String format, Object... arguments) {
        System.out.println(this.name + ":" + marker + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + marker + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.info(marker, format, arguments);
        }
    }

    @Override
    public void info(Marker marker, String msg, Throwable t) {
        System.out.println(this.name + ":" + marker + msg + t);
        System.err.println(this.name + ":" + marker + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.info(marker, msg, t);
        }
    }

    @Override
    public boolean isWarnEnabled() {
        return true;
    }

    @Override
    public void warn(String msg) {
        System.out.println(this.name + ":" + msg);
        System.err.println(this.name + ":" + msg);

        if (null != this.logger) {
            this.logger.warn(msg);
        }
    }

    @Override
    public void warn(String format, Object arg) {
        System.out.println(this.name + ":" + format + arg);
        System.err.println(this.name + ":" + format + arg);

        if (null != this.logger) {
            this.logger.warn(format, arg);
        }
    }

    @Override
    public void warn(String format, Object... arguments) {
        System.out.println(this.name + ":" + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.warn(format, arguments);
        }
    }

    @Override
    public void warn(String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + format + arg1 + arg2);
        System.err.println(this.name + ":" + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.warn(format, arg1, arg2);
        }
    }

    @Override
    public void warn(String msg, Throwable t) {
        System.out.println(this.name + ":" + msg + t);
        System.err.println(this.name + ":" + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.warn(msg, t);
        }
    }

    @Override
    public boolean isWarnEnabled(Marker marker) {
        return true;
    }

    @Override
    public void warn(Marker marker, String msg) {
        System.out.println(this.name + ":" + marker + msg);
        System.err.println(this.name + ":" + marker + msg);

        if (null != this.logger) {
            this.logger.warn(marker, msg);
        }
    }

    @Override
    public void warn(Marker marker, String format, Object arg) {
        System.out.println(this.name + ":" + marker + format + arg);
        System.err.println(this.name + ":" + marker + format + arg);

        if (null != this.logger) {
            this.logger.warn(marker, format, arg);
        }
    }

    @Override
    public void warn(Marker marker, String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + marker + format + arg1 + arg2);
        System.err.println(this.name + ":" + marker + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.warn(marker, format, arg1, arg2);
        }
    }

    @Override
    public void warn(Marker marker, String format, Object... arguments) {
        System.out.println(this.name + ":" + marker + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + marker + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.warn(marker, format, arguments);
        }
    }

    @Override
    public void warn(Marker marker, String msg, Throwable t) {
        System.out.println(this.name + ":" + marker + msg + t);
        System.err.println(this.name + ":" + marker + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.warn(marker, msg, t);
        }
    }

    @Override
    public boolean isErrorEnabled() {
        return true;
    }

    @Override
    public void error(String msg) {
        System.out.println(this.name + ":" + msg);
        System.err.println(this.name + ":" + msg);

        if (null != this.logger) {
            this.logger.error(msg);
        }
    }

    @Override
    public void error(String format, Object arg) {
        System.out.println(this.name + ":" + format + arg);
        System.err.println(this.name + ":" + format + arg);

        if (null != this.logger) {
            this.logger.error(format, arg);
        }
    }

    @Override
    public void error(String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + format + arg1 + arg2);
        System.err.println(this.name + ":" + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.error(format, arg1, arg2);
        }
    }

    @Override
    public void error(String format, Object... arguments) {
        System.out.println(this.name + ":" + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.error(format, arguments);
        }
    }

    @Override
    public void error(String msg, Throwable t) {
        System.out.println(this.name + ":" + msg + t);
        System.err.println(this.name + ":" + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.error(msg, t);
        }
    }

    @Override
    public boolean isErrorEnabled(Marker marker) {
        return true;
    }

    @Override
    public void error(Marker marker, String msg) {
        System.out.println(this.name + ":" + marker + msg);
        System.err.println(this.name + ":" + marker + msg);

        if (null != this.logger) {
            this.logger.error(marker, msg);
        }
    }

    @Override
    public void error(Marker marker, String format, Object arg) {
        System.out.println(this.name + ":" + marker + format + arg);
        System.err.println(this.name + ":" + marker + format + arg);

        if (null != this.logger) {
            this.logger.error(marker, format, arg);
        }
    }

    @Override
    public void error(Marker marker, String format, Object arg1, Object arg2) {
        System.out.println(this.name + ":" + marker + format + arg1 + arg2);
        System.err.println(this.name + ":" + marker + format + arg1 + arg2);

        if (null != this.logger) {
            this.logger.error(marker, format, arg1, arg2);
        }
    }

    @Override
    public void error(Marker marker, String format, Object... arguments) {
        System.out.println(this.name + ":" + marker + format + Arrays.toString(arguments));
        System.err.println(this.name + ":" + marker + format + Arrays.toString(arguments));

        if (null != this.logger) {
            this.logger.error(marker, format, arguments);
        }
    }

    @Override
    public void error(Marker marker, String msg, Throwable t) {
        System.out.println(this.name + ":" + marker + msg + t);
        System.err.println(this.name + ":" + marker + msg + t);

        t.printStackTrace();

        if (null != this.logger) {
            this.logger.error(marker, msg, t);
        }
    }
}